﻿using RSSReader.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace RSSReader.WCFWebRole
{
  //[DataContract]
  public partial class UserSubscriptionInformation
  {
    //[DataMember]
    //public int SourceId { get; set; }
    //[DataMember]
    //public string Url { get; set; }
    //[DataMember]
    //public string UserId { get; set; }
    //[DataMember]
    //public bool IsSubscribe { get; set; }
    //[DataMember]
    //public string Title { get; set; }
    //[DataMember]
    //public string Description { get; set; }

    public UserSubscriptionInformation() { }

    public UserSubscriptionInformation(UserSubscriptionVW userSub)
    {
      this.SourceId = userSub.SourceId;
      this.Url = userSub.Url;
      this.UserId = userSub.UserId;
      this.IsSubscribe = userSub.IsSubscribe;
      this.Title = userSub.Title;
      this.Description = userSub.Description;
    }
  }

  //[DataContract]
  public partial class UserArticleInformation
  {
    //[DataMember]
    //public string Url { get; set; }
    //[DataMember]
    //public int ArticleId { get; set; }
    //[DataMember]
    //public bool IsFavorite { get; set; }
    //[DataMember]
    //public string UserId { get; set; }
    //[DataMember]
    //public string Title { get; set; }
    //[DataMember]
    //public string Description { get; set; }
    //[DataMember]
    //public DateTime? PublicationDate { get; set; }

    public UserArticleInformation() { }

    public UserArticleInformation(UserArticleVW userArticle)
    {
      this.Url = userArticle.Url;
      this.ArticleId = userArticle.ArticleId;
      this.IsFavorite = userArticle.IsFavorite;
      this.UserId = userArticle.UserId;
      this.Title = userArticle.Title;
      this.Description = userArticle.Description;
      this.PublicationDate = userArticle.PublicationDate;
    }
  }

  //[DataContract]
  public partial class UserInformation
  {
    //[DataMember]
    //public string Id { get; set; }
    //[DataMember]
    //public string UserName { get; set; }
    //[DataMember]
    //public string PasswordHash { get; set; }
    //[DataMember]
    //public string Email { get; set; }

    public UserInformation() { }

    public UserInformation(ApplicationUser user)
    {
      if (user != null)
      {
        this.UserName = user.UserName;
        this.PasswordHash = user.PasswordHash;
        this.Email = user.Email;
        this.Id = user.Id;
      }
    }

  }

  [ServiceContract]
  public interface IDataDistributor
  {
    [OperationContract]
    string GetUserId(string userName);
    [OperationContract]
    UserInformation GetUser(string userName, string passwordHash);
    [OperationContract]
    IEnumerable<UserInformation> GetUsers();
    [OperationContract]
    UserInformation CreateUser(string userName, string passwordHash, string email);
    [OperationContract]
    IEnumerable<UserSubscriptionInformation> GetSubscriptions(string userId);
    [OperationContract]
    void RemoveSubscriptions(IEnumerable<string> subs, string userId);
    [OperationContract]
    void SetSubscriptions(IEnumerable<UserSubscriptionInformation> subs, string userId);
    [OperationContract]
    void UpdateUserArticles(Dictionary<UserSubscriptionInformation, IEnumerable<UserArticleInformation>> feeds, string userId);
    [OperationContract]
    Dictionary<string, IEnumerable<UserArticleInformation>> GetUserArticles(IEnumerable<string> feedsUrl, string userId);
    [OperationContract]
    Dictionary<UserSubscriptionInformation, IEnumerable<UserArticleInformation>> GetUserFavorites(string userId);
  }
}